package edu.ynu.se.xiecheng.achitectureclass.entity;

import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 大棚信息实体类
 * 用于存储大棚的基本信息，包括名称、地址、面积以及关联的设备
 */
@Entity
@Table(name = "plantation")
@Data
@EqualsAndHashCode(callSuper = true, exclude = "equipments")
@ToString(exclude = "equipments")
public class Plantation extends LogicEntity {

    /**
     * 大棚名称
     * 非空，最长255字符
     */
    @Column(name = "plantation_name", nullable = false, length = 255)
    private String plantationName;

    /**
     * 大棚地址
     * 非空，最长500字符
     */
    @Column(name = "plantation_address", nullable = false, length = 500)
    private String plantationAddress;

    /**
     * 大棚面积
     * 非空
     */
    @Column(name = "plantation_area", nullable = false)
    private Double plantationArea;

    /**
     * 关联的设备集合
     * 大棚与设备的一对多关系
     */
    @OneToMany(mappedBy = "plantation", fetch = FetchType.EAGER)
    private Set<Equipment> equipments = new HashSet<>();
}